import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from "path";
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [uni()],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "./src/uni.scss";',
      },
    },
  },
  server: {
    port: 5177, // 改为实际运行的端口
    host: "0.0.0.0", // 允许局域网访问
    cors: true, // 启用CORS
    strictPort: true, // 如果端口已被占用则会直接退出
    proxy: {
      "/api": {
        target: "https://fishpi.cn",
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, ""),
        configure: (proxy, options) => {
          proxy.on("error", (err, req, res) => {
            console.log("代理错误", err);
          });
          proxy.on("proxyReq", (proxyReq, req, res) => {
            console.log("代理请求:", req.method, req.url);
          });
          proxy.on("proxyRes", (proxyRes, req, res) => {
            console.log("代理响应:", proxyRes.statusCode, req.url);
          });
        },
      },
      "/activity": {
        target: "https://fishpi.cn",
        changeOrigin: true,
        secure: false,
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
});
